package hr.fer.apr.ht41337.lab2;

import java.io.*;

import hr.fer.apr.ht41337.lab2.funkcije.*;

public class Glavni {

	public static void main(String[] args) {

		File minf2 = new File("minf2.txt");
		BufferedReader br;
		String line;
		Tocka x0 = null;
		String[] tocka;
		double e = 1e-9;
		double a = 1.3;
		try {
			br = new BufferedReader(new FileReader(minf2));
			line = br.readLine();
			tocka = line.split(" ");
			x0 = new Tocka(tocka.length);
			for (int i = 0; i < x0.dimenzija; i++)
				x0.setX(i, Double.parseDouble(tocka[i]));
			e = Double.parseDouble(br.readLine());
			a = Double.parseDouble(br.readLine());
			FunkcijaOgranicena f = new F2();
			Tocka min = MinimizacijaPoBoxu.minimum(f, x0, e, a);
			System.out.println("Minimum funkcije f2 -> " + min);
		} catch (FileNotFoundException ex) {
			System.out.println(ex.getMessage());
		} catch (IOException ex) {
			System.out.println(ex.getMessage());
			System.exit(1);
		} catch (IllegalArgumentException ex){
			System.out.println(ex.getMessage());
		}
		
		File f3 = new File("f3.txt");
		File minf3 = new File("minf3.txt");
		try {
			br = new BufferedReader(new FileReader(minf3));
			line = br.readLine();
			tocka = line.split(" ");
			x0 = new Tocka(tocka.length);
			for (int i = 0; i < x0.dimenzija; i++)
				x0.setX(i, Double.parseDouble(tocka[i]));
			e = Double.parseDouble(br.readLine());
			a = Double.parseDouble(br.readLine());
			FunkcijaOgranicena f = new F3(f3);
			Tocka min = MinimizacijaPoBoxu.minimum(f, x0, e, a);
			System.out.println("Minimum funkcije f3 -> " + min);
		} catch (FileNotFoundException ex) {
			System.out.println(ex.getMessage());
		} catch (IOException ex) {
			System.out.println(ex.getMessage());
			System.exit(1);
		} catch (IllegalArgumentException ex){
			System.out.println(ex.getMessage());
		}
		
		
	}

}
